//
//  UIBarButtonItem+Extension.swift
//  SinaBlog
//
//  Created by 李超 on 16/3/23.
//  Copyright © 2016年 lichao. All rights reserved.
//

import UIKit

//对系统的类进行拓展，与oc中的category类似
extension UIBarButtonItem{
    
    //便利构造函数
    convenience init(imageName:String,hightLightImageName:String,target: AnyObject?,action:Selector,Events:UIControlEvents) {
      
      let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
    
        btn.setBackgroundImage(UIImage(named: hightLightImageName), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        btn.addTarget(target, action: action, forControlEvents: Events)
    
        self.init(customView:btn)
    }
    //便利构造函数
    convenience init(imageName:String,target: AnyObject?,action:Selector,Events:UIControlEvents) {
        
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        btn.addTarget(target, action: action, forControlEvents: Events)
        
        self.init(customView:btn)
    }
    
    //便利构造函数
    convenience init(title:String,target: AnyObject?,action:Selector){
        
        let btn = UIButton()
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.sizeToFit()
        btn.titleLabel?.font = UIFont.systemFontOfSize(16)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Disabled)
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        self.init(customView:btn)
    }
    
}
